﻿namespace Rio.Manager.Application.Views
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Rio.Manager.Application.ViewModel.Administration;
    using NetBay.Core.BusinessEntities.Connectors;
    using Telerik.Windows.Controls.GridView;
    using Telerik.Windows.Controls;
    using System.ComponentModel;

    public partial class ConnectorTabView : UserControl
    {       
        #region Constructors

        public ConnectorTabView()
        {
            InitializeComponent();            
        }
        
        #endregion Constructors

        #region Event

        /// <summary>Handles the SelectionChanged event of the RadGridView_Connector_Information control.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.SelectionChangeEventArgs" /> instance containing the event data.</param>
        public void RadGridView_Connector_Information_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
        {
            //Setter the connector correspondence list.
            (DataContext as ConnectorTabViewModel).ConnectorInformationsSelected = new System.Collections.ObjectModel.ObservableCollection<Connector>(RadGridView_Connector_Information.SelectedItems.Cast<Connector>());

            //Built the good context menu.
            SetIsEnabledProprtiesContextMenu();
        }

        /// <summary>Handles the Opened event of the RadGridView_Connector_Information control.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.SelectionChangeEventArgs" /> instance containing the event data.</param>
        private void ContextMenu_Connector_Information_Opened(object sender, RoutedEventArgs e)
        {
            ////Built the good context menu.
            SetIsEnabledProprtiesContextMenu();
        }

        #endregion Event

        #region Method

        /// <summary>Set the context menu enable properties.</summary>
        private void SetIsEnabledProprtiesContextMenu()
        {
            //Built the good context menu.
            switch ((DataContext as ConnectorTabViewModel).ConnectorInformationsSelected.Count())
            {
                case 0:
                    //ContextMenu_Connector_Information.Visibility = Visibility.Collapsed;
                    (DataContext as ConnectorTabViewModel).CanAddConnector = false;
                    (DataContext as ConnectorTabViewModel).CanUpdateConnector = false;
                    (DataContext as ConnectorTabViewModel).CanDeleteConnector = false;
                    (DataContext as ConnectorTabViewModel).CanRefreshConnector = false;
                    break;
                case 1:
                    //ContextMenu_Connector_Information.Visibility = Visibility.Visible;
                    (DataContext as ConnectorTabViewModel).CanAddConnector = true;
                    (DataContext as ConnectorTabViewModel).CanUpdateConnector = true;
                    (DataContext as ConnectorTabViewModel).CanDeleteConnector = true;
                    (DataContext as ConnectorTabViewModel).CanRefreshConnector = true;
                    break;
                default:
                    //ContextMenu_Connector_Information.Visibility = Visibility.Visible;
                    (DataContext as ConnectorTabViewModel).CanAddConnector = true;
                    (DataContext as ConnectorTabViewModel).CanUpdateConnector = false;
                    (DataContext as ConnectorTabViewModel).CanDeleteConnector = true;
                    (DataContext as ConnectorTabViewModel).CanRefreshConnector = true;
                    break;
            }
        }

        #endregion Method
    }
}